package cn.cdeden.knowledge.service.impl;import cn.cdeden.common.core.utils.MapstructUtils;import cn.cdeden.common.core.utils.StringUtils;import cn.cdeden.common.core.utils.page.TableDataInfo;import cn.cdeden.common.mybatis.validator.QueryHelpMybatisPlus;import cn.cdeden.common.oss.enumd.OssBucketOneEnum;import cn.cdeden.common.oss.enumd.OssModuleType;import cn.cdeden.common.satoken.utils.LoginHelper;import cn.cdeden.knowledge.domain.*;import cn.cdeden.knowledge.domain.dto.*;import cn.cdeden.knowledge.domain.enums.MessageTypeEnums;import cn.cdeden.knowledge.domain.vo.EnterpriseMemberVo;import cn.cdeden.knowledge.enums.*;import cn.cdeden.knowledge.enums.TeamFilesTreeRenameParam;import cn.cdeden.knowledge.mapper.EnterpriseFolderTreeMapper;import cn.cdeden.knowledge.mapper.FilesCollectionMapper;import cn.cdeden.knowledge.service.*;import cn.cdeden.knowledge.utils.FileUtil;import cn.cdeden.knowledge.utils.PageUtil;import cn.cdeden.knowledge.vo.EnterpriseFilesTreeVO;import cn.cdeden.resource.api.RemoteFileService;import cn.cdeden.resource.api.RemoteOssEsService;import cn.cdeden.resource.api.domain.RemoteEsFilesTree;import cn.cdeden.resource.api.domain.RemoteFile;import cn.cdeden.resource.api.domain.RemoteFilesDownload;import cn.cdeden.resource.api.domain.RemoteFilesUpload;import cn.cdeden.system.api.RemoteDictService;import cn.cdeden.system.api.RemoteDifyService;import cn.cdeden.system.api.RemoteUserService;import cn.cdeden.system.api.domain.bo.RemoteDifyCreateByFileBo;import cn.cdeden.system.api.domain.enums.EnterprisePermTypeEnum;import cn.cdeden.system.api.domain.enums.FileTypeEnum;import cn.cdeden.system.api.domain.vo.RemoteDictDataVo;import cn.cdeden.system.api.domain.vo.RemoteDifyCreateByFileVo;import cn.cdeden.system.api.domain.vo.RemoteUserVo;import cn.cdeden.system.api.model.LoginUser;import cn.hutool.core.util.ObjectUtil;import com.alibaba.fastjson2.JSONObject;import com.baomidou.lock.annotation.Lock4j;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;import com.baomidou.mybatisplus.core.metadata.IPage;import io.undertow.util.BadRequestException;import jakarta.validation.constraints.NotBlank;import lombok.RequiredArgsConstructor;import org.apache.commons.collections4.CollectionUtils;import org.apache.dubbo.config.annotation.DubboReference;import org.springframework.data.domain.Pageable;import org.springframework.stereotype.Service;import java.util.*;import java.util.stream.Collectors;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;import cn.cdeden.knowledge.mapper.EnterpriseFilesTreeMapper;import org.springframework.transaction.annotation.Transactional;@Service@RequiredArgsConstructorpublic class EnterpriseFilesTreeServiceImpl extends ServiceImpl<EnterpriseFilesTreeMapper, EnterpriseFilesTree> implements EnterpriseFilesTreeService {    private final EnterpriseFilesTreeMapper enterpriseFilesTreeMapper;    @DubboReference(check = false)    private final RemoteUserService remoteUserService;    private final FilesCollectionMapper filesCollectionMapper;    private final EnterprisePermService enterprisePermService;    @DubboReference(check = false)    private final RemoteDictService remoteDictService;    @DubboReference(check = false)    private final RemoteFileService remoteFileService;    private final EnterpriseFolderTreeMapper enterpriseFolderTreeMapper;    @DubboReference(check = false)    private final RemoteDifyService remoteDifyService;    private final FilesAttentionService filesAttentionService;    private final SysMessageService messageService;    private final RemoteOssEsService remoteOssEsService;    @Override    public EnterpriseFilesTreeDto queryList(EnterpriseFilesTreeQueryParam query, Boolean isCheckPerm) {        insertInitData(Long.valueOf(query.getParentId()));        String parentId = query.getParentId();        if (parentId == null) throw new RuntimeException("传递id为空");        //查询本级节点        EnterpriseFilesTree enterpriseFilesTree = enterpriseFilesTreeMapper.selectById(parentId);//        EnterpriseFilesTreeDto enterpriseFilesTreeDto = ConvertUtil.convert(enterpriseFilesTree, EnterpriseFilesTreeDto.class);        EnterpriseFilesTreeDto enterpriseFilesTreeDto = MapstructUtils.convert(enterpriseFilesTree, EnterpriseFilesTreeDto.class);//        FileUserDto user = FileUserUtils.getUser();        LoginUser user = LoginHelper.getLoginUser();        Long userId = user.getUserId();        //查询子级节点        query.setId(null);        ArrayList<String> strings = new ArrayList<>();        strings.add(TreeTypeEnum.FILE.getType());        strings.add(TreeTypeEnum.RICHTEXT.getType());        enterpriseFilesTreeDto.setChildren(getEnterpriseFilesTreeList(query, userId, isCheckPerm, strings));        if (isCheckPerm) {            //查询权限            String perms = enterprisePermService.getPerms(Long.valueOf(parentId),userId);            enterpriseFilesTreeDto.setPerm(perms);        }        return enterpriseFilesTreeDto;//        return null;    }    @Override    public TableDataInfo<EnterpriseFilesTreeDto> queryAll(EnterpriseFilesTreeQueryParam query, Pageable pageable) {        String parentId = query.getParentId();        if (!StringUtils.isNotEmpty(parentId)) {            insertInitData(Long.valueOf(parentId));        }        query.setId(null);        QueryWrapper<EnterpriseFilesTree> predicate = QueryHelpMybatisPlus.getPredicate(query);        predicate.lambda().isNotNull(EnterpriseFilesTree::getParentId).isNull(EnterpriseFilesTree::getDeleteId);        LoginUser user = LoginHelper.getLoginUser();        Long userId = user.getUserId();        TableDataInfo<EnterpriseFilesTreeDto> enterpriseFilesTreePage = getEnterpriseFilesTreePage(query, userId, pageable);        return enterpriseFilesTreePage;    }    @Override    public EnterpriseFilesTreeDto queryAll(EnterpriseFilesTreeQueryParam query, Boolean isCheckPerm) {        String ids = query.getId();        if (!StringUtils.isNullOrBlank(ids)) {            insertInitData(Long.valueOf(ids));        }        String id = query.getId();        if (id == null) throw new RuntimeException("传递id为空");        //查询本级节点        EnterpriseFilesTree enterpriseFilesTree = enterpriseFilesTreeMapper.selectById(id);        EnterpriseFilesTreeDto enterpriseFilesTreeDto = MapstructUtils.convert(enterpriseFilesTree, EnterpriseFilesTreeDto.class);        LoginUser loginUser = LoginHelper.getLoginUser();        Long userId = loginUser.getUserId();        //查询子级节点        query.setId(null);        query.setParentId(id);        enterpriseFilesTreeDto.setChildren(getEnterpriseFilesTreeList(query, userId, isCheckPerm, null));        if (isCheckPerm) {            //查询权限            String perms = enterprisePermService.getPerms(Long.valueOf(id), userId);            enterpriseFilesTreeDto.setPerm(perms);        }        return enterpriseFilesTreeDto;    }    @Override    public EnterpriseFilesTreeDto insertData(EnterpriseFilesTreeDto resources, Boolean isException) {        String parentId = resources.getParentId();        LoginUser user = LoginHelper.getLoginUser();//        FileUserDto user = FileUserUtils.getUser();        if (org.apache.commons.lang3.StringUtils.isEmpty(parentId)) throw new RuntimeException("文件夹id为空");        //检查在此文件夹下是否有权限        Boolean flag = false;        EnterpriseFilesTree entry = null;        EnterpriseFilesTree enterpriseFilesTree = baseMapper.selectById(parentId);        if (parentId.equals("1")) {/*            flag = enterprisePermService.isEnterpriseAdminOrAdmin(null);            if (!flag) throw new RuntimeException("没有权限新增文件夹");*/            //赋予文件夹类型            resources.setType(FileTypeEnum.FOLDER.getCode());            //新增文件夹            entry = insert(resources, isException);            //新增libraryId            baseMapper.update(new LambdaUpdateWrapper<EnterpriseFilesTree>().eq(EnterpriseFilesTree::getId, resources.getId()).set(EnterpriseFilesTree::getLibraryId, resources.getId()));            //新增第一层文件夹权限            enterprisePermService.insertOneFolderPerm(resources.getId(), Long.valueOf(parentId), user.getUserId(), EnterprisePermTypeEnum.MANAGE);//            enterprisePermService.insertOneFolderPerm(resources.getId(), Long.valueOf(parentId), user.getId(), EnterprisePermTypeEnum.MANAGE);        } else {            flag = enterprisePermService.checkPermission(Long.valueOf(parentId), EnterprisePermTypeEnum.EDITOR, null);//            flag = enterprisePermService.checkPermission(Long.valueOf(parentId), EnterprisePermTypeEnum.EDITOR, null);            if (!flag) throw new RuntimeException("没有权限新增文件夹");            //赋予文件夹类型            resources.setType(FileTypeEnum.FOLDER.getCode());            resources.setLibraryId(enterpriseFilesTree.getLibraryId());            //新增文件夹            entry = insert(resources, isException);            enterprisePermService.extendPerm(Long.valueOf(parentId), resources.getId());//            enterprisePermService.extendPerm(Long.valueOf(parentId), resources.getId());        }//        List<EnterpriseFilesTree> filesTrees = baseMapper.selectSuperiorAll(parentId);//        for (EnterpriseFilesTree filesTree : filesTrees) {            //TODO:插入消息//            List<FilesCollection> filesCollections = filesCollectionMapper.selectList(new LambdaQueryWrapper<FilesCollection>().eq(FilesCollection::getTreeNodeId, filesTree.getId()).eq(FilesCollection::getFileType, "2"));//            List<FilesCollection> filesCollections = filesCollectionMapper.lambdaQuery().eq(FilesCollection::getTreeNodeId, filesTree.getId()).eq(FilesCollection::getFileType, "2").list();//            List<String> collect = filesCollections.stream().map(FilesCollection::getUserId).distinct().collect(Collectors.toList());            //TODO 消息//            messageUtils.createList(MessageTypeChildEnums.ENTERPRISE_FOLDER, filesTree.getId().toString(), user.getId().toString(), collect, "你关注的文件夹\"" + filesTree.getRealName() + "\"下新增了文件夹\"" + resources.getRealName() + "\"");//        }        //TODO 创建日志        //创建日志//        sysDocLogService.createLog(String.valueOf(resources.getId()), user, TreeEnum.ENTERPRISE, OperationEnum.INSERT.getOperation(OperationEnum.OperationTypeEnum.FOLDER), entry.getRealName(), entry.getPath(), null);        return resources;    }    @Override    public void insertRemark(Long id, String remark) {        LoginUser loginUser = LoginHelper.getLoginUser();        if (!enterprisePermService.checkPermission(id, EnterprisePermTypeEnum.MANAGE, loginUser.getUserId()))            throw new RuntimeException("没有权限操作");        EnterpriseFilesTree byId = getById(id);        if (byId == null || StringUtils.isNullOrBlank(remark)) return;        byId.setRemarks(remark);        baseMapper.updateById(byId);    }    @Override    public EnterpriseFilesTree createFile(RemoteFilesUpload remoteFilesUpload, String parentId, String realName, String abstractName, String author, String fileEncode, String userId, String userName,String fileDatasetId,LoginUser user) {//        if (!remoteFilesUpload.getBucketName().equals(remoteFilesUpload.ENTERPRISE_BUCKET.getCode()))//            throw new BadRequestException("传递参数fileStorage不是企业桶中文件");        if (!StringUtils.isNullOrBlank(fileEncode)) realName = fileEncode + "-" + realName;        EnterpriseFilesTree parentTree = getById(parentId);        EnterpriseFilesTreeDto enterpriseFilesTree = new EnterpriseFilesTreeDto();        enterpriseFilesTree.setRealName(realName);        enterpriseFilesTree.setParentId(parentId);        enterpriseFilesTree.setLibraryId(parentTree.getLibraryId());        enterpriseFilesTree.setSuffix(remoteFilesUpload.getFileSuffix());        enterpriseFilesTree.setStorageId(remoteFilesUpload.getStorageId().toString());        enterpriseFilesTree.setCreateId(String.valueOf(userId));        enterpriseFilesTree.setCreateBy(userName);        enterpriseFilesTree.setFileDatasetId(fileDatasetId);        enterpriseFilesTree.setPath(parentTree.getPath() + "/" + realName);        enterpriseFilesTree.setSuperiorsPath(parentTree.getPath());        enterpriseFilesTree.setType(FileTypeEnum.FILE.getCode());//        enterpriseFilesTree.setStorageType(remoteFilesUpload.getStorageType());        enterpriseFilesTree.setSize(remoteFilesUpload.getFileSize());        enterpriseFilesTree.setEditionName(remoteFilesUpload.getVersionName());        enterpriseFilesTree.setEdition(remoteFilesUpload.getVersionId());        enterpriseFilesTree.setFileEncode(fileEncode);        if (!StringUtils.isNullOrBlank(abstractName)) enterpriseFilesTree.setRemarks(abstractName);        setParentNodeSize(parentId, remoteFilesUpload.getFileSize(), 0);        return insert(enterpriseFilesTree, true,user);    }    private void insertInitData(Long id) {        if (id.longValue() == 1) {//            SysParametersConfigDto companyName = sysConfigUtils.getByConfigCodeAfter("companyName", SysParametersConfigEnums.SYS_GENERAL_CONFIG);//            String configValue = companyName.getConfigValue();            String configValue = "企业知识库";            if (enterpriseFilesTreeMapper.selectById(1) == null) {                EnterpriseFilesTree enterpriseFilesTree = new EnterpriseFilesTree();                enterpriseFilesTree.setId(1L);                enterpriseFilesTree.setRealName(configValue);                enterpriseFilesTree.setSuperiorsPath("/");                enterpriseFilesTree.setPath("/" + configValue);                enterpriseFilesTree.setType(TreeTypeEnum.FOLDER.getType());                baseMapper.insert(enterpriseFilesTree);            }        }    }    public List<EnterpriseFilesTreeDto> getEnterpriseFilesTreeList(EnterpriseFilesTreeQueryParam query, Long userId, Boolean isCheckPerm, List<String> filtration) {//        FileUserDto user = FileUserUtils.getUserInfo(userId.toString());        LoginUser loginUser = LoginHelper.getLoginUser();        query.setUserId(loginUser.getUserId());        RemoteUserVo user = remoteUserService.selectUserByUserId(userId);        QueryWrapper<EnterpriseFilesTree> predicate = QueryHelpMybatisPlus.getPredicate(query);        QueryWrapper<EnterpriseFilesTree> predicate2 = QueryHelpMybatisPlus.getPredicate(query);        predicate.lambda().isNull(EnterpriseFilesTree::getDeleteId);        List<EnterpriseFilesTreeDto> enterpriseFilesTreeDtos = null;        //过滤文件        if (filtration != null && filtration.size() > 0) {            predicate.lambda().notIn(EnterpriseFilesTree::getType, filtration);        }        if (isCheckPerm) {            //判断是否为超级管理员/*            if (LoginHelper.isSuperAdmin(userId)) {                //如果不是超级管理员                List<EnterprisePerm> permsByParentTreeNodeId = enterprisePermService.getPerms(Long.valueOf(query.getParentId()), userId, EnterprisePermTypeEnum.QUERY);//                List<EnterprisePerm> permsByParentTreeNodeId = enterprisePermService.getPerms(Long.valueOf(query.getParentId()), userId, EnterprisePermTypeEnum.QUERY);                //获取文件ids                List<Long> enterpriseIds = permsByParentTreeNodeId.stream().map(EnterprisePerm::getTreeNodeId).collect(Collectors.toList());//                if (enterpriseIds.size() == 0) return new ArrayList<EnterpriseFilesTreeDto>();                predicate2.lambda().eq(EnterpriseFilesTree::getCreateId, userId);                List<EnterpriseFilesTree> enterpriseFilesTrees = enterpriseFilesTreeMapper.selectList(predicate2);                List<Long> collect = enterpriseFilesTrees.stream().map(EnterpriseFilesTree::getId).collect(Collectors.toList());                enterpriseIds.addAll(collect);                List<Long> collect1 = enterpriseIds.stream().distinct().collect(Collectors.toList());                if (collect1.size() == 0) return new ArrayList<EnterpriseFilesTreeDto>();                predicate.lambda().in(EnterpriseFilesTree::getId, collect1);            }*/            if (!enterprisePermService.isAdmin(userId)) {                //如果不是超级管理员                List<EnterprisePerm> permsByParentTreeNodeId = enterprisePermService.getPerms(Long.valueOf(query.getParentId()), userId, EnterprisePermTypeEnum.QUERY);                //获取文件ids                List<Long> enterpriseIds = permsByParentTreeNodeId.stream().map(EnterprisePerm::getTreeNodeId).collect(Collectors.toList());//                if (enterpriseIds.size() == 0) return new ArrayList<EnterpriseFilesTreeDto>();                predicate2.lambda().eq(EnterpriseFilesTree::getCreateId,userId);                List<EnterpriseFilesTree> enterpriseFilesTrees = enterpriseFilesTreeMapper.selectList(predicate2);                List<Long> collect = enterpriseFilesTrees.stream().map(EnterpriseFilesTree::getId).collect(Collectors.toList());                enterpriseIds.addAll(collect);                List<Long> collect1 = enterpriseIds.stream().distinct().collect(Collectors.toList());                if (collect1.size() == 0) return new ArrayList<EnterpriseFilesTreeDto>();                predicate.lambda().in(EnterpriseFilesTree::getId, collect1);            }            /**             *             */            //TODO：生效日期未做业务处理            enterpriseFilesTreeDtos = enterpriseFilesTreeMapper.selectEnterpriseList(predicate, query);            enterpriseFilesTreeDtos.stream().forEach(action -> {                Long id = action.getId();                action.setPerm(enterprisePermService.getPerms(id, userId));            });        } else {            enterpriseFilesTreeDtos = enterpriseFilesTreeMapper.selectEnterpriseList(predicate, query);        }        return enterpriseFilesTreeDtos;    }    public TableDataInfo<EnterpriseFilesTreeDto> getEnterpriseFilesTreePage(EnterpriseFilesTreeQueryParam query, Long userId, Pageable pageable) {//        FileUserDto user = FileUserUtils.getUserInfo(userId.toString());        LoginUser loginUser = LoginHelper.getLoginUser();        query.setUserId(loginUser.getUserId());        QueryWrapper<EnterpriseFilesTree> predicate = QueryHelpMybatisPlus.getPredicate(query);        QueryWrapper<EnterpriseFilesTree> predicate2 = QueryHelpMybatisPlus.getPredicate(query);        predicate.lambda().isNull(EnterpriseFilesTree::getDeleteId);        if (!enterprisePermService.isAdmin(userId)) {            //如果不是管理员            String realName = query.getRealName();            //查询文件夹下的权限文件夹id            List<EnterprisePerm> permsByParentTreeNodeId = null;            List<Long> enterpriseIds = new ArrayList<>();            if (StringUtils.isNotEmpty(realName)) {                permsByParentTreeNodeId = enterprisePermService.getPerms((Long) null, userId, EnterprisePermTypeEnum.QUERY);                //获取文件ids                enterpriseIds = permsByParentTreeNodeId.stream().map(EnterprisePerm::getTreeNodeId).collect(Collectors.toList());//                if (enterpriseIds.size() == 0) return new PageInfo<EnterpriseFilesTreeDto>();                ////////////////////////////////////////////////////////////////////////////            } else {                permsByParentTreeNodeId = enterprisePermService.getPerms(!StringUtils.isNotEmpty(query.getParentId()) ? (Long) null : Long.valueOf(query.getParentId()), userId, EnterprisePermTypeEnum.QUERY);                //获取文件ids                enterpriseIds = permsByParentTreeNodeId.stream().map(EnterprisePerm::getTreeNodeId).collect(Collectors.toList());//                if (enterpriseIds.size() == 0) return new PageInfo<EnterpriseFilesTreeDto>();                ////////////////////////////////////////////////////////////////////////////            }            predicate2.lambda().eq(EnterpriseFilesTree::getCreateId, userId);            List<EnterpriseFilesTree> enterpriseFilesTrees = enterpriseFilesTreeMapper.selectList(predicate2);            List<Long> collect = enterpriseFilesTrees.stream().map(EnterpriseFilesTree::getId).collect(Collectors.toList());            enterpriseIds.addAll(collect);            List<Long> collect1 = enterpriseIds.stream().distinct().collect(Collectors.toList());            if (collect1.size() == 0) return new TableDataInfo<EnterpriseFilesTreeDto>();            predicate.lambda().in(EnterpriseFilesTree::getId, collect1);        }        IPage<EnterpriseFilesTreeDto> queryPage = PageUtil.toMybatisPage(pageable);        IPage<EnterpriseFilesTreeDto> page = enterpriseFilesTreeMapper.selectEnterprisePage(predicate, query, queryPage);        List<EnterpriseFilesTreeDto> records = page.getRecords();        records.forEach(action -> {            action.setPerm(enterprisePermService.getPerms(action.getId(), userId));            String insertPerm = action.getInsertPerm();            //添加人的权限            EnterprisePermTypeEnum permTypeEnum = null;            if (insertPerm == null || StringUtils.isEmpty(insertPerm)) {                permTypeEnum = EnterprisePermTypeEnum.MANAGE;            } else {                permTypeEnum = EnterprisePermTypeEnum.getPermTypeEnum(insertPerm);            }            String perms = action.getPerm();            EnterprisePermTypeEnum personPerm = EnterprisePermTypeEnum.getPermTypeEnum(perms);            if (permTypeEnum.getPermRank() >= personPerm.getPermRank()) action.setIsInsertPerm(true);            else action.setIsInsertPerm(false);        });        //TODO：生效日期未做业务处理        TableDataInfo<EnterpriseFilesTreeDto> build = TableDataInfo.build(page);//        return ConvertUtil.convertPage(page, EnterpriseFilesTreeDto.class, pageable);        return build;    }    @Transactional(rollbackFor = Exception.class)    public EnterpriseFilesTree insert(EnterpriseFilesTreeDto resources, Boolean isException,LoginUser loginUser) {//        EnterpriseFilesTree entity = ConvertUtil.convert(resources, EnterpriseFilesTree.class);        EnterpriseFilesTree entity = MapstructUtils.convert(resources, EnterpriseFilesTree.class);        EnterpriseFilesTree select = nameRechecking(entity.getRealName(), entity.getParentId(), entity.getSuffix());        if (select == null) {            if (StringUtils.isEmpty(entity.getCreateId())) {                entity.setCreateId(String.valueOf(loginUser.getUserId()));            }            if (StringUtils.isEmpty(entity.getCreateBy())) {                entity.setCreateBy(loginUser.getNickname());            }            if (entity.getCreateTime() == null) {                entity.setCreateTime(new Date());            }            if (StringUtils.isEmpty(entity.getUpdateId())) {                entity.setUpdateId(String.valueOf(loginUser.getUserId()));            }            if (StringUtils.isEmpty(entity.getUpdateBy())) {                entity.setUpdateBy(loginUser.getNickname());            }            //文件路径            EnterpriseFilesTree enterpriseFilesTree = getById(resources.getParentId());            entity.setSuperiorsPath(enterpriseFilesTree.getPath());            if (null == enterpriseFilesTree.getPath()) {                entity.setPath("/" + resources.getRealName());            } else {                entity.setPath(enterpriseFilesTree.getPath() + "/" + resources.getRealName());            }            enterpriseFilesTreeMapper.insert(entity);            resources.setId(entity.getId());            return entity;        } else {            if (isException) {                throw new RuntimeException("该文件名已存在!");            } else {                resources.setId(select.getId());                return select;            }        }    }    @Override    @Transactional(rollbackFor = Exception.class)    public EnterpriseFilesTree insert(EnterpriseFilesTreeDto resources, Boolean isException) {        return insert(resources,isException,LoginHelper.getLoginUser());    }    @Override    public EnterpriseFilesTree nameRechecking(String realName, String parentId, String suffix) {        EnterpriseFilesTreeQueryParam query = new EnterpriseFilesTreeQueryParam();        QueryWrapper<EnterpriseFilesTree> predicate = QueryHelpMybatisPlus.getPredicate(query);        predicate.eq("real_name", realName);        predicate.eq("parent_id", parentId);        if (suffix == null) {            predicate.isNull("suffix");        } else {            predicate.eq("suffix", suffix);        }        predicate.isNull("delete_id");        List<EnterpriseFilesTree> enterpriseFilesTree = enterpriseFilesTreeMapper.selectList(predicate);        if (enterpriseFilesTree.size()>0){            return enterpriseFilesTree.get(0);        }else {            return null;        }    }    @Override    public void topMark(FilesTreeTop top) {        LoginUser user = LoginHelper.getLoginUser();//        FileUserDto user = FileUserUtils.getUser();        List<String> ids = top.getIds();        boolean isTop = top.isTop();        if (ids == null) throw new RuntimeException("传递参数为空");        for (String id : ids) {            if (id == null) throw new RuntimeException("id为空");            EnterpriseFilesTree enterpriseFilesTree = enterpriseFilesTreeMapper.selectById(id);            if (enterpriseFilesTree == null) throw new RuntimeException("文件不存在");            Boolean aBoolean = enterprisePermService.checkPermission(Long.valueOf(id), EnterprisePermTypeEnum.MANAGE, user.getUserId());//            Boolean aBoolean = enterprisePermService.checkPermission(Long.valueOf(id), EnterprisePermTypeEnum.MANAGE, user.getId());            if (!aBoolean) throw new RuntimeException("没有操作权限");        }        enterpriseFilesTreeMapper.update(new LambdaUpdateWrapper<EnterpriseFilesTree>().in(EnterpriseFilesTree::getId, top.getIds()).set(EnterpriseFilesTree::getSort, isTop ? -1 : 0));//        baseMapper.lambdaUpdate().in(EnterpriseFilesTree::getId, top.getIds()).set(EnterpriseFilesTree::getSort, isTop ? -1 : 0).update();    }    /**     * 修改所有上级文件夹的大小     *     * @param parentId     * @param size     * @param addAndMinus 0是增加所有上级大小 1是减少所有上级大小     */    @Override    public void setParentNodeSize(String parentId, Long size, int addAndMinus) {        if (size == null) {            size = 0L;        }        EnterpriseFilesTree parentFile = getById(parentId);        if (addAndMinus == 0) {            if (null == parentFile.getSize()) {                parentFile.setSize(size);            } else {                parentFile.setSize(parentFile.getSize() + size);            }        } else {            parentFile.setSize(parentFile.getSize() - size);        }        enterpriseFilesTreeMapper.updateById(parentFile);        if (null != parentFile.getParentId()) {            setParentNodeSize(parentFile.getParentId(), size, addAndMinus);        }    }    @Override    public List<String> getChildAllById(String id) {        List<String> ids = new ArrayList<>();        EnterpriseFilesTreeQueryParam enterpriseFilesTreeQueryParam = new EnterpriseFilesTreeQueryParam();        QueryWrapper<EnterpriseFilesTree> predicate = QueryHelpMybatisPlus.getPredicate(enterpriseFilesTreeQueryParam);        predicate.eq("parent_id", id);        predicate.isNull("delete_id");        predicate.eq("type", "folder");        List<EnterpriseFilesTree> enterpriseFilesTrees = enterpriseFilesTreeMapper.selectList(predicate);        for (int i = 0; i < enterpriseFilesTrees.size(); i++) {            EnterpriseFilesTree enterpriseFilesTree = enterpriseFilesTrees.get(i);            ids.add(String.valueOf(enterpriseFilesTree.getId()));        }        return ids;    }    @Override    public void rechristen(TeamFilesTreeRenameParam dto) throws BadRequestException {        Long id = dto.getId();        EnterpriseFilesTree byId = getById(id);        //检查是否有权限        Boolean aBoolean = enterprisePermService.checkPermission(dto.getId(), EnterprisePermTypeEnum.EDITOR, null);//        Boolean aBoolean = enterprisePermService.checkPermission(dto.getId(), EnterprisePermTypeEnum.EDITOR, null);        if (!aBoolean) throw new RuntimeException("没有编辑权限");        else {            EnterpriseFilesTreeDto resources = new EnterpriseFilesTreeDto();            resources.setId(id);            resources.setRealName(dto.getRealName());            boolean rename = false;            if (null != dto.getRealName()) {                rename = rename(resources);            }            if (!rename) {                throw new RuntimeException("该文件名已存在");            }            createFileToEs(resources.getId());        }        LoginUser loginUser = LoginHelper.getLoginUser();        //添加消息        EnterpriseFilesTree enterpriseFilesTree = baseMapper.selectById(id);        List<TreeNodeDto> parentTreeNodeAll = queryEnterpriseFiles(String.valueOf(enterpriseFilesTree.getId()));        for (int i = 0; i < parentTreeNodeAll.size(); i++) {            String id2 = parentTreeNodeAll.get(i).getId();            List<String> attentionPeople = filesAttentionService.getAttentionPeople(id2, "2");            for (int j = 0; j < attentionPeople.size(); j++) {                //创建消息                SysMessageDto sysMessageDto = new SysMessageDto();                sysMessageDto.setContent("您关注的文件夹/文件名为“" + byId.getRealName() + "”,已被用户昵称为“" + loginUser.getNickname() + "”更名为“"+dto.getRealName()+"”");                sysMessageDto.setOperator(loginUser.getUserId().toString());                sysMessageDto.setNodeId(parentTreeNodeAll.get(i).getId().toString());                sysMessageDto.setMessageType("0");                sysMessageDto.setType(MessageTypeEnums.UPDATE.getCode());                sysMessageDto.setFileType(MessageFileTypeEnums.ENTERPRISE.getCode());                sysMessageDto.setRecipient(attentionPeople.get(j));                sysMessageDto.setTeamId(String.valueOf(enterpriseFilesTree.getLibraryId()));                messageService.addMessage(sysMessageDto);            }        }    }    @Override    public List<TreeNodeDto> queryEnterpriseFiles(String treeNodeId) {        List<TreeNodeDto> list = new ArrayList<>();        EnterpriseFilesTree enterpriseFilesTree = getById(treeNodeId);        if (enterpriseFilesTree == null){            throw new RuntimeException("文件已删除");        }        list.add(new TreeNodeDto(String.valueOf(enterpriseFilesTree.getId()), enterpriseFilesTree.getRealName()));        String parentId = enterpriseFilesTree.getParentId();        while (parentId != null) {            EnterpriseFilesTree enterpriseFilesTreeParent = getById(parentId);            list.add(new TreeNodeDto(String.valueOf(enterpriseFilesTreeParent.getId()), enterpriseFilesTreeParent.getRealName()));            if (enterpriseFilesTreeParent.getParentId() == null) {                break;            }            parentId = enterpriseFilesTreeParent.getParentId();        }        return list;    }    @Override    public boolean rename(EnterpriseFilesTreeDto enterpriseFilesTreeDto) {        EnterpriseFilesTree enterpriseFilesTree = getById(enterpriseFilesTreeDto.getId());        if (nameRechecking(enterpriseFilesTreeDto.getRealName(), enterpriseFilesTree.getParentId(), enterpriseFilesTree.getSuffix()) != null) {            return false;        }        //修改自身路径        enterpriseFilesTree.setRealName(enterpriseFilesTreeDto.getRealName());        if (enterpriseFilesTree.getSuperiorsPath() != null) {            enterpriseFilesTree.setPath(enterpriseFilesTree.getSuperiorsPath() + "/" + enterpriseFilesTree.getRealName());        } else {            enterpriseFilesTree.setPath("/" + enterpriseFilesTree.getRealName());        }        LoginUser loginUser = LoginHelper.getLoginUser();        enterpriseFilesTree.setUpdateId(String.valueOf(loginUser.getUserId()));        enterpriseFilesTree.setUpdateBy(loginUser.getNickname());        enterpriseFilesTreeMapper.updateById(enterpriseFilesTree);        //修改它的所有子文件的路径        renameChild(enterpriseFilesTree);        return true;    }    @Override    public TableDataInfo<FilesTree> searchFilesTree(SearchFilesInfoDto infoDto, Pageable pageable) {//        FileUserDto user = FileUserUtils.getUser();        LoginUser user = LoginHelper.getLoginUser();        Long userId = user.getUserId();//        if (!enterprisePermService.isAdmin(userId)) {        if (!enterprisePermService.isAdmin(userId)) {            //如果不是管理员            //查询文件夹下的权限文件夹id            List<EnterprisePerm> permsByParentTreeNodeId = null;//            permsByParentTreeNodeId = enterprisePermService.getPerms((Long) null, userId, EnterprisePermTypeEnum.QUERY);            permsByParentTreeNodeId = enterprisePermService.getPerms((Long) null, userId, EnterprisePermTypeEnum.QUERY);//            permsByParentTreeNodeId = MapstructUtils.convert(enterprisePermService.getPerms((Long) null, userId, EnterprisePermTypeEnum.QUERY), EnterprisePerm.class);            //获取文件ids            List<Long> enterpriseIds = permsByParentTreeNodeId.stream().map(EnterprisePerm::getTreeNodeId).collect(Collectors.toList());//            if (enterpriseIds.size() == 0) return new PageInfo<FilesTree>();            if (enterpriseIds.size() == 0) return new TableDataInfo<>();            infoDto.setIds(enterpriseIds);        }        IPage queryPage = PageUtil.toMybatisPage(pageable);        IPage<FilesTree> filesTreeIPage = enterpriseFilesTreeMapper.searchTree(infoDto, queryPage);        TableDataInfo<FilesTree> build = TableDataInfo.build(filesTreeIPage);//        return ConvertUtil.convertPage(filesTreeIPage, FilesTree.class ,pageable);        return build;    }    @Override    public List<FilesTree> selectFilesTree(Collection<String> ids) {        QueryWrapper<EnterpriseFilesTree> predicate = new QueryWrapper<>();        predicate.in("id", ids)//                .eq("type",TreeTypeEnum.FILE.getType())            .isNull("delete_id");        List<EnterpriseFilesTree> trees = this.list(predicate);        return CollectionUtils.isEmpty(trees) ? null : MapstructUtils.convert(MapstructUtils.convert(trees, EnterpriseFilesTreeDto.class), FilesTree.class);    }    @Override    public List<FilesTree> selectFilesTree(Collection<String> ids, String userId) {        return selectFilesTree(ids, userId, true);    }    /**     * ids查询用户是否有权限     *     * @param ids     * @param userId     * @param b     * @return     */    @Override    public List<FilesTree> selectFilesTree(Collection<String> ids, String userId, boolean b) {        List<Long> iDs = ids.stream().map(s -> Long.valueOf(s.trim())).collect(Collectors.toList());        EnterpriseFilesTreeQueryParam enterpriseFilesTreeQueryParam = new EnterpriseFilesTreeQueryParam();        enterpriseFilesTreeQueryParam.setIds(iDs);        List<EnterpriseFilesTreeDto> children = checkEnterpriseFilesTreeBy(enterpriseFilesTreeQueryParam, EnterprisePermTypeEnum.QUERY, Long.valueOf(userId));        return CollectionUtils.isEmpty(children) ? null : MapstructUtils.convert(children, FilesTree.class);    }    public List<EnterpriseFilesTreeDto> checkEnterpriseFilesTreeBy(EnterpriseFilesTreeQueryParam query, EnterprisePermTypeEnum enterprisePermTypeEnum, Long userId) {//        LoginUser loginUser = LoginHelper.getLoginUser();        query.setUserId(userId);        QueryWrapper<EnterpriseFilesTree> predicate = QueryHelpMybatisPlus.getPredicate(query);        predicate.lambda().isNull(EnterpriseFilesTree::getDeleteId);        List<Long> ids = query.getIds();        List<Long> parentIds = query.getParentIds();        if (!enterprisePermService.isAdmin(userId)) {            //如果不是管理员            //查询文件夹下的权限文件夹id            EnterprisePermQueryParam enterprisePermQueryParam = new EnterprisePermQueryParam();            enterprisePermQueryParam.setTreeNodeId(ids);            enterprisePermQueryParam.setParentTreeNodeId(parentIds);            List<Long> enterpriseIds = enterprisePermService.getPerms(enterprisePermQueryParam, userId, enterprisePermTypeEnum);            if (enterpriseIds.size() == 0) return new ArrayList<EnterpriseFilesTreeDto>();            predicate.lambda().in(EnterpriseFilesTree::getId, enterpriseIds);        } else {            predicate.lambda().in(ids != null && ids.size() > 0, EnterpriseFilesTree::getId, ids).in(parentIds != null && parentIds.size() > 0, EnterpriseFilesTree::getParentId, parentIds);        }        //TODO：生效日期未做业务处理        List<EnterpriseFilesTreeDto> enterpriseFilesTreeDtos = enterpriseFilesTreeMapper.selectEnterpriseList(predicate, query);        return enterpriseFilesTreeDtos;    }    public void renameChild(EnterpriseFilesTree enterpriseFilesTree) {        EnterpriseFilesTreeQueryParam enterpriseFilesTreeQueryParam = new EnterpriseFilesTreeQueryParam();        QueryWrapper<EnterpriseFilesTree> predicate = QueryHelpMybatisPlus.getPredicate(enterpriseFilesTreeQueryParam);        predicate.eq("parent_id", enterpriseFilesTree.getId());        predicate.isNull("delete_id");        List<EnterpriseFilesTree> enterpriseFilesTrees = enterpriseFilesTreeMapper.selectList(predicate);        if (enterpriseFilesTrees.size() > 0) {            for (int i = 0; i < enterpriseFilesTrees.size(); i++) {                EnterpriseFilesTree child = enterpriseFilesTrees.get(i);                child.setSuperiorsPath(enterpriseFilesTree.getPath());                child.setPath(enterpriseFilesTree.getPath() + "/" + child.getRealName());                enterpriseFilesTreeMapper.updateById(child);                renameChild(enterpriseFilesTrees.get(i));            }        }    }    @Override    public HeadKnowLab queryKnowLab(EnterpriseFilesTreeQueryParam query, Boolean isCheckPerm) {        query.setParentId("1");        EnterpriseFilesTreeDto enterpriseFilesTreeDto = queryList(query, isCheckPerm);        List<EnterpriseFilesTreeDto> children = enterpriseFilesTreeDto.getChildren();        Map<String, List<EnterpriseFilesTreeDto>> collect = children.stream().sorted(Comparator.comparingInt(EnterpriseFilesTreeDto::getSort))            .collect(Collectors.groupingBy(EnterpriseFilesTreeDto::getClassify));        List<RemoteDictDataVo> wikiType = remoteDictService.selectDictDataByType("wiki_type");        List<KnowLab> knowLabs = new ArrayList<>();        collect.forEach((k, v) -> {            String classifyName = k;            for (RemoteDictDataVo remoteDictDataVo : wikiType) {                if (remoteDictDataVo.getDictValue().equals(k)){                    classifyName = remoteDictDataVo.getDictLabel();                    break;                }            }            knowLabs.add(new KnowLab(classifyName, v));        });        return new HeadKnowLab(enterpriseFilesTreeDto.getPerm(), knowLabs);    }    @Override    public List<KnowLab> queryKnowLab() {        Map<String, List<EnterpriseFilesTree>> collect = enterpriseFilesTreeMapper.lambdaQuery().eq(EnterpriseFilesTree::getParentId, "1").isNull(EnterpriseFilesTree::getDeleteId).list().stream().sorted(Comparator.comparingInt(EnterpriseFilesTree::getSort))            .collect(Collectors.groupingBy(EnterpriseFilesTree::getClassify));        List<RemoteDictDataVo> wikiType = remoteDictService.selectDictDataByType("wiki_type");        List<KnowLab> knowLabs = new ArrayList<>();        collect.forEach((k, v) -> {            String classifyName = k;            for (RemoteDictDataVo remoteDictDataVo : wikiType) {                if (remoteDictDataVo.getDictValue().equals(k)){                    classifyName = remoteDictDataVo.getDictLabel();                    break;                }            }            knowLabs.add(new KnowLab(classifyName, MapstructUtils.convert(v,EnterpriseFilesTreeDto.class)));        });        return knowLabs;    }    @Override    public Boolean newBuiltKnowLab(@NotBlank String classify, @NotBlank String name, String remark, @NotBlank String imageUrl, String kowLabId, String templateId,String location,Integer sort) {        EnterpriseFilesTreeDto enterpriseFilesTreeDto = new EnterpriseFilesTreeDto();        enterpriseFilesTreeDto.setClassify(classify);        enterpriseFilesTreeDto.setParentId("1");        enterpriseFilesTreeDto.setRealName(name);        enterpriseFilesTreeDto.setRemarks(remark);        enterpriseFilesTreeDto.setImageUrl(imageUrl);        enterpriseFilesTreeDto.setAiDatasetId(kowLabId);        enterpriseFilesTreeDto.setLocation(location);        enterpriseFilesTreeDto.setSort(sort);        EnterpriseFilesTreeDto enterpriseFilesTreeDto1 = insertData(enterpriseFilesTreeDto, true);        if (StringUtils.isNotBlank(templateId)) {            EnterpriseFilesTree byId = getById(enterpriseFilesTreeDto1.getId());            List<EnterpriseFolderTree> enterpriseFolderTrees = getFolderTreeChildren(templateId);            createByTemplateChild(enterpriseFolderTrees,byId,byId.getLibraryId());            //查找文件权限            List<EnterprisePerm> list = enterprisePermService.lambdaQuery().eq(EnterprisePerm::getTreeNodeId, enterpriseFilesTreeDto1.getId()).list();            //权限设置            List<EnterpriseFilesTree> list1 = baseMapper.lambdaQuery().eq(EnterpriseFilesTree::getParentId, byId.getId()).list();            list1.forEach(action->{                ArrayList<EnterprisePermDto> enterprisePermDtos = new ArrayList<>();                list.forEach(enterprisePerm->{                    EnterprisePermDto enterprisePermDto = new EnterprisePermDto();                    enterprisePermDto.setTreeNodeId(action.getId());                    enterprisePermDto.setPermCodes(enterprisePerm.getParams());                    enterprisePermDto.setParams(enterprisePerm.getParams());                    enterprisePermDto.setType(enterprisePerm.getType());                    enterprisePermDto.setTypeId(enterprisePerm.getTypeId());                    enterprisePermDtos.add(enterprisePermDto);                });                enterprisePermService.insertPermissionsByTreeNodeIds(enterprisePermDtos, action.getId());            });        }        return true;    }    @Override    public void editKnowLab(Long id, @NotBlank String realName, @NotBlank String classify, String remarks, @NotBlank String imageUrl,String location,Integer sort) {        EnterpriseFilesTree enterpriseFilesTree = new EnterpriseFilesTree();        enterpriseFilesTree.setId(id);        enterpriseFilesTree.setRealName(realName);        enterpriseFilesTree.setClassify(classify);        enterpriseFilesTree.setImageUrl(imageUrl);        enterpriseFilesTree.setRemarks(remarks);        enterpriseFilesTree.setLocation(location);        enterpriseFilesTree.setSort(sort);        updateById(enterpriseFilesTree);    }    @Override    public void deleteKnowLab(Long id) {        LoginUser loginUser = LoginHelper.getLoginUser();        baseMapper.lambdaUpdate().eq(EnterpriseFilesTree::getId, id).set(EnterpriseFilesTree::getDeleteId, loginUser.getUserId()).set(EnterpriseFilesTree::getDeleteType, DeleteTypeEnums.LIBRARY_DELETE.getType()).update();    }    @Override    public List<EnterpriseFilesTree> nameRecheckingVerifyData(String parentId) {        return enterpriseFilesTreeMapper.nameRecheckingVerifyData(parentId);    }    @Override    @Transactional(rollbackFor = Exception.class)    public EnterpriseFilesTreeDto createFolderFilePath(String parentId, String path) {        String[] split = path.split("/");        EnterpriseFilesTreeDto tree = null;        for (String folderName : split) {            EnterpriseFilesTreeDto enterpriseFilesTreeDto = new EnterpriseFilesTreeDto();            enterpriseFilesTreeDto.setParentId(parentId);            enterpriseFilesTreeDto.setRealName(folderName);            tree = insertData(enterpriseFilesTreeDto, false);            parentId = String.valueOf(tree.getId());        }        return tree;    }    @Override    public List<RemoteFilesDownload> folderSonFiles(List<String> ids, String userId, Boolean b, EnterprisePermTypeEnum enterprisePermTypeEnum) {        List<Long> parentIds = ids.stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());        EnterpriseFilesTreeQueryParam enterpriseFilesTreeQueryParam = new EnterpriseFilesTreeQueryParam();        enterpriseFilesTreeQueryParam.setParentIds(parentIds);        List<EnterpriseFilesTreeDto> trees = checkEnterpriseFilesTreeBy(enterpriseFilesTreeQueryParam, enterprisePermTypeEnum, Long.valueOf(userId));//        List<RemoteFilesDownload> treeList = MapstructUtils.convert(trees, RemoteFilesDownload.class);        List<RemoteFilesDownload> treeList = new ArrayList<>();        if (CollectionUtils.isNotEmpty(trees)) {            List<String> list1 = new ArrayList<>();            trees.forEach(tree -> {                RemoteFilesDownload remoteFilesDownload = new RemoteFilesDownload();                remoteFilesDownload.setId(tree.getId().toString());                remoteFilesDownload.setParentId(tree.getParentId());                remoteFilesDownload.setDateId(String.valueOf(tree.getId()));                remoteFilesDownload.setStorageId(tree.getStorageId());                remoteFilesDownload.setVersionId(tree.getEdition());                remoteFilesDownload.setVersionName(tree.getEditionName());                remoteFilesDownload.setFileSize(tree.getSize());                remoteFilesDownload.setFileSuffix(tree.getSuffix());                remoteFilesDownload.setFileName(tree.getRealName());                remoteFilesDownload.setLibraryType(OssModuleType.Enterprise.getCode());                remoteFilesDownload.setFolder(org.apache.commons.lang3.StringUtils.equalsIgnoreCase(TreeTypeEnum.FOLDER.getType(), tree.getType()));                treeList.add(remoteFilesDownload);                if (org.apache.commons.lang3.StringUtils.equalsIgnoreCase(TreeTypeEnum.FOLDER.getType(), tree.getType())) {                    list1.add(String.valueOf(tree.getId()));                }            });            if (CollectionUtils.isNotEmpty(list1)) {                List<RemoteFilesDownload> list = folderSonFiles(list1, userId, b, enterprisePermTypeEnum);                if (CollectionUtils.isNotEmpty(list)) {                    for (RemoteFilesDownload tree : treeList) {                        String id = String.valueOf(tree.getDateId());                        List<RemoteFilesDownload> filesTreeList = new ArrayList<>();                        for (RemoteFilesDownload filesTree : list) {                            String parentId = filesTree.getParentId();                            if (org.apache.commons.lang3.StringUtils.equals(id, parentId)) {                                filesTreeList.add(filesTree);                            }                        }                        tree.setChildren(filesTreeList);                    }                }            }        }        return treeList;    }    @Override    public List<DataItem> getAllParentId(String parentId) {        ArrayList<DataItem> strings = new ArrayList<>();        getParentId(parentId,strings);        return strings;    }    @Override    public int selectByIdTreePageInfo(String userId, List<Long> deptIds, List<Long> roles, List<Long> jobIds, String treeId, String parentId, Integer size, List<String> sort, Boolean isPerm) {        int i;        if (isPerm){            i = enterpriseFilesTreeMapper.selectByIdTreePageInfoPerm( userId,deptIds,roles,jobIds , treeId, parentId, size, sort);        }else {            i = enterpriseFilesTreeMapper.selectByIdTreePageInfoNoPerm( userId , treeId, parentId, size, sort);        }        return i;    }    public void getParentId(String parentId,ArrayList<DataItem> strings){        EnterpriseFilesTree one = enterpriseFilesTreeMapper.lambdaQuery().eq(EnterpriseFilesTree::getId, parentId).one();        strings.add(new DataItem(one.getRealName(),one.getId().toString()));        if (one.getParentId() == null)return;        getParentId(one.getParentId(),strings);    }    //获得文件树    @Override    public EnterpriseFilesTreeDto getFolder(Long templateId) {        if (ObjectUtil.isNull(templateId)) throw new RuntimeException("模板id为空");        EnterpriseFilesTree byId = enterpriseFilesTreeMapper.selectById(templateId);        if (ObjectUtil.isNull(byId)) throw new RuntimeException("模板文件夹不存在,请重新创建");//        byId.setPath(ImageFileUrlUtil.imageFile(byId.getPath()));//        EnterpriseFilesTree byId1 = getById(byId.getParentId());        EnterpriseFilesTreeDto convert = MapstructUtils.convert(byId, EnterpriseFilesTreeDto.class);        select(convert);        return convert;    }    public void select(EnterpriseFilesTreeDto enterpriseFilesTreeDto) {        List<EnterpriseFilesTree> list = lambdaQuery().eq(EnterpriseFilesTree::getParentId, enterpriseFilesTreeDto.getId()).isNull(EnterpriseFilesTree::getDeleteType).list();        List<EnterpriseFilesTreeDto> convert = MapstructUtils.convert(list, EnterpriseFilesTreeDto.class);        enterpriseFilesTreeDto.setChildren(convert);        for (EnterpriseFilesTreeDto enterpriseFilesTree : convert) {            select(enterpriseFilesTree);        }    }    /**     * 分类下知识库数量     */    @Override    public List<AnalysisData> analysisKnowLab() {        List<KnowLab> knowLabs = queryKnowLab(new EnterpriseFilesTreeQueryParam(), true).getHeads();        ArrayList<AnalysisData> analysisData = new ArrayList<>();        for (KnowLab knowLab : knowLabs) {            List<EnterpriseFilesTreeDto> tree = knowLab.getTree();            List<EnterpriseFilesTreeDto> list = tree.stream().filter(entry -> {                return entry.getAiDatasetId() != null;            }).toList();            int size = knowLab.getTree().size();            String classifyName = knowLab.getClassifyName();            analysisData.add(new AnalysisData(classifyName, list.size(),size-list.size(), knowLab.getTree(),null));        }        return analysisData;    }    @Override    public TableDataInfo<EnterpriseFilesTreeDto> commonAnalysisKnowLab(Pageable pageable) {        EnterpriseFilesTreeQueryParam query = new EnterpriseFilesTreeQueryParam();        query.setParentId("1");        TableDataInfo<EnterpriseFilesTreeDto> enterpriseFilesTreeDtoTableDataInfo = queryAll(query, pageable);        List<RemoteDictDataVo> wikiType = remoteDictService.selectDictDataByType("wiki_type");        for (EnterpriseFilesTreeDto filesTreeDto : enterpriseFilesTreeDtoTableDataInfo.getRows()) {            for (RemoteDictDataVo wikiTypeVo : wikiType){                if (wikiTypeVo.getDictValue().equals(filesTreeDto.getClassify())){                    filesTreeDto.setClassifyName(wikiTypeVo.getDictLabel());                }            }        }        return enterpriseFilesTreeDtoTableDataInfo;    }    @Override    public void updateDify(List<Long> ids){        List<EnterpriseFilesTree> list = enterpriseFilesTreeMapper.lambdaQuery().in(EnterpriseFilesTree::getId, ids).list();        list.forEach(action->{            EnterpriseFilesTree byId = getById(action.getId());            String fileDatasetId1 = byId.getFileDatasetId();            if (fileDatasetId1 != null){                RemoteDifyCreateByFileBo remoteDifyCreateByFileBo = new RemoteDifyCreateByFileBo();                remoteDifyCreateByFileBo.setIndexing_technique("high_quality");                RemoteDifyCreateByFileBo.ProcessingRule processingRule = new RemoteDifyCreateByFileBo.ProcessingRule();                remoteDifyCreateByFileBo.setProcess_rule(processingRule);                RemoteDifyCreateByFileBo.ProcessingRule.Rules rules = new RemoteDifyCreateByFileBo.ProcessingRule.Rules();                processingRule.setRules(rules);                processingRule.setMode("custom");                ArrayList<RemoteDifyCreateByFileBo.ProcessingRule.Rules.PreProcessingRule> preProcessingRules = new ArrayList<>();                rules.setPre_processing_rules(preProcessingRules);                preProcessingRules.add(new RemoteDifyCreateByFileBo.ProcessingRule.Rules.PreProcessingRule("remove_extra_spaces", true));                preProcessingRules.add(new RemoteDifyCreateByFileBo.ProcessingRule.Rules.PreProcessingRule("remove_urls_emails", true));                rules.setSegmentation(new RemoteDifyCreateByFileBo.ProcessingRule.Rules.Segmentation("###", 500));                EnterpriseFilesTree byId2 = getById(action.getLibraryId());                RemoteDifyCreateByFileVo byFile = remoteDifyService.createByFile(byId.getStorageId().toString(), byId.getRealName() + "-" + byId.getEditionName(), byId2.getAiDatasetId(), remoteDifyCreateByFileBo);                String id = byFile.getDocument().getId();                enterpriseFilesTreeMapper.lambdaUpdate().eq(EnterpriseFilesTree::getId, action.getId()).set(EnterpriseFilesTree::getFileDatasetId, id).update();                Boolean delete = remoteDifyService.delete(byId2.getAiDatasetId(), fileDatasetId1);                if (!delete) {                    throw new RuntimeException("文件删除失败");                }            }        });    }    @Override    public EnterpriseFilesTreeVO getPortalFile(Long fileId) {        Map<String, List<EnterpriseFilesTreeVO>> enterpriseFilesTreeMap = new HashMap<>(16);        List<EnterpriseFilesTree> enterpriseFilesTrees = enterpriseFilesTreeMapper.selectList(new QueryWrapper<EnterpriseFilesTree>().eq("id", fileId).or().eq("parent_id", fileId));        Optional<EnterpriseFilesTree> first = enterpriseFilesTrees.stream().filter(enterpriseFilesTree -> enterpriseFilesTree.getId().equals(fileId)).findFirst();        EnterpriseFilesTree enterpriseFilesTree = first.orElse(null);        EnterpriseFilesTreeVO enterpriseFilesTreeVO = MapstructUtils.convert(enterpriseFilesTree, EnterpriseFilesTreeVO.class);        List<EnterpriseFilesTree> enterpriseFilesTreeList = enterpriseFilesTrees.stream().filter(enterpriseFilesTree1 -> enterpriseFilesTree1.getParentId().equals(fileId.toString())).collect(Collectors.toList());        List<EnterpriseFilesTreeVO> enterpriseFilesTreeVOS = MapstructUtils.convert(enterpriseFilesTreeList, EnterpriseFilesTreeVO.class);        enterpriseFilesTreeVO.setChildrenList(enterpriseFilesTreeVOS);        //再查询下一层的数据        List<EnterpriseFilesTreeVO> childrenList = enterpriseFilesTreeVO.getChildrenList();        List<Long> parentIds = childrenList.stream().map(EnterpriseFilesTreeVO::getId).collect(Collectors.toList());        if (!parentIds.isEmpty()) {            List<EnterpriseFilesTree> enterpriseFilesTreeList1 = enterpriseFilesTreeMapper.selectList(new QueryWrapper<EnterpriseFilesTree>().in("parent_id", parentIds));            List<EnterpriseFilesTreeVO> enterpriseFilesTreeVOS1 = MapstructUtils.convert(enterpriseFilesTreeList1, EnterpriseFilesTreeVO.class);            enterpriseFilesTreeMap = enterpriseFilesTreeVOS1.stream().collect(Collectors.groupingBy(EnterpriseFilesTreeVO::getParentId, Collectors.toList()));        }        Map<String, List<EnterpriseFilesTreeVO>> finalEnterpriseFilesTreeMap = enterpriseFilesTreeMap;        childrenList.forEach(v -> {            if (finalEnterpriseFilesTreeMap.containsKey(v.getId().toString())) {                v.setChildrenList(finalEnterpriseFilesTreeMap.get(v.getId().toString()));            }        });        enterpriseFilesTreeVO.setChildrenList(childrenList);        return enterpriseFilesTreeVO;    }    /**     * 团队文档(中间表)归档到企业库     *     * @param teamToEnterpriseDto(必传参数id,parentId,type,realName,suffix,path,superiorsPath,size)     * @param userId     * @param username     * @param parentId     * @param count                                                                          强制传1，代表第一次进入，头文件夹     */    @Override    public void createFolder(TeamToEnterpriseDto teamToEnterpriseDto, String userId, String abstractName, String username, String parentId, int count) {        if (ObjectUtil.isNull(teamToEnterpriseDto)) throw new RuntimeException("文件夹id为空");        //查子文件夹        List<TeamToEnterpriseDto> list = teamToEnterpriseDto.getChildren();        //临时表//        ArrayList<EnterpriseFilesTree> enterpriseFilesTrees = new ArrayList<>();//        for (TeamToEnterprise toEnterprise : list) {        EnterpriseFilesTreeDto enterpriseFilesTree = new EnterpriseFilesTreeDto();        enterpriseFilesTree.setSuffix(teamToEnterpriseDto.getSuffix());        if (teamToEnterpriseDto.getType().equals(FileTypeEnum.FILE.getCode())) {            //移动文件            RemoteFile remoteFile = new RemoteFile();            remoteFile.setOssId(Long.valueOf(teamToEnterpriseDto.getStorageId()));            remoteFile = remoteFileService.copyFile(remoteFile, OssBucketOneEnum.ENTERPRISE_BUCKET.getCode(), OssModuleType.Enterprise);//            Storage storage = fileStorageUtils.copy(userId, username, FileEnums.ENTERPRISE_FILE, StorageFolderTypeEnum.TEMPLATE_BUCKET.getCode(), teamToEnterpriseDto.getStorageId(), null, null);//            Storage storage = fileStorageUtils.moveTitle(userId, username, null, teamToEnterpriseDto.getRealName(), StorageFolderTypeEnum.TEMPLATE_BUCKET.getCode(), teamToEnterpriseDto.getStorageId(), FileEnums.ENTERPRISE_FILE);            enterpriseFilesTree.setSuffix(remoteFile.getFileSuffix());            enterpriseFilesTree.setStorageId(remoteFile.getOssId().toString());            enterpriseFilesTree.setSize(remoteFile.getFileSize());        }        enterpriseFilesTree.setParentId(parentId);        enterpriseFilesTree.setSize(teamToEnterpriseDto.getSize());        enterpriseFilesTree.setRealName(teamToEnterpriseDto.getRealName());        enterpriseFilesTree.setType(teamToEnterpriseDto.getType());        enterpriseFilesTree.setSuperiorsPath(teamToEnterpriseDto.getPath());        enterpriseFilesTree.setPath(teamToEnterpriseDto.getPath() + "/" + teamToEnterpriseDto.getRealName());        enterpriseFilesTree.setUpdateBy(username);        //更新路径        teamToEnterpriseDto.setSuperiorsPath(enterpriseFilesTree.getSuperiorsPath()).setPath(enterpriseFilesTree.getPath());//        }        //插入文件夹        if (count == 1) {            enterpriseFilesTree.setRemarks(abstractName);        }        insert(enterpriseFilesTree,true);//        saveBatch(enterpriseFilesTrees);        Long id = enterpriseFilesTree.getId();        //表单文档//        if (teamToEnterpriseDto.getType().equals(FileTypeEnum.RICH_TEXT.getCode())) {//            String sysFormDocDtoJson = teamToEnterpriseDto.getFormDocJson();//            SysFormDocDto sysFormDocDto = com.alibaba.fastjson.JSONObject.parseObject(sysFormDocDtoJson, SysFormDocDto.class);////            //创建表单文档//            sysFormDocDto.setType("2");//            sysFormDocDto.setTreeNodeId(String.valueOf(enterpriseFilesTree.getId()));//            sysFormDocDto.setId(null);//            SysFormDoc insert = sysFormDocService.insert(sysFormDocDto);////            //复制表单文档下的文件到minio//            String storagesJson = teamToEnterpriseDto.getStoragesJson();//            List<Storage> storages = com.alibaba.fastjson.JSONObject.parseArray(storagesJson, Storage.class);//            for (Storage value : storages) {//                //临时库移动到企业库////                Storage storage = fileStorageUtils.moveTitle(userId, username, null, value.getRealName(), StorageFolderTypeEnum.FORM_DOC_FILES.getCode(), String.valueOf(value.getStorageId()), FileEnums.ENTERPRISE_FORM_DOC_FILE);//                Storage storage = fileStorageUtils.copy(userId, username, FileEnums.ENTERPRISE_FORM_DOC_FILE,//                    StorageFolderTypeEnum.FORM_DOC_FILES.getCode(), String.valueOf(value.getStorageId()), null, value.getRealName());//////                //创建表单文档文件//                SysFormDocFileDto sysFormDocFileDto = new SysFormDocFileDto();//                sysFormDocFileDto.setTreeNodeId(String.valueOf(enterpriseFilesTree.getId()));//                sysFormDocFileDto.setFormDocId(String.valueOf(insert.getId()));//                sysFormDocFileDto.setStorageId(String.valueOf(storage.getStorageId()));//                sysFormDocFileDto.setFileName(storage.getRealName());//                sysFormDocFileDto.setSuffix(storage.getSuffix());//                sysFormDocFileDto.setSize(storage.getSize());//                sysFormDocFileService.insert(sysFormDocFileDto);//            }//        }        //权限继承        enterprisePermService.extendPerm(Long.valueOf(parentId), id);        //更新大小（第一层）        if (count == 1) {            setParentNodeSize(parentId, teamToEnterpriseDto.getSize(), 0);        }        count++;        for (TeamToEnterpriseDto toEnterprise : list) {            createFolder(toEnterprise, userId, null, username, id.toString(), count);        }    }    @Override    public void createFolder(PersonalToEnterpriseDto toEnterpriseDto, String userId, String abstractName, String username, String parentId, int count) throws BadRequestException {        if (ObjectUtil.isNull(toEnterpriseDto)) throw new BadRequestException("文件夹id为空");        //查子文件夹        List<PersonalToEnterpriseDto> list = toEnterpriseDto.getChildren();        //临时表//        ArrayList<EnterpriseFilesTree> enterpriseFilesTrees = new ArrayList<>();//        for (TeamToEnterprise toEnterprise : list) {        EnterpriseFilesTreeDto enterpriseFilesTree = new EnterpriseFilesTreeDto();        enterpriseFilesTree.setSuffix(toEnterpriseDto.getSuffix());        if (toEnterpriseDto.getType().equals(FileTypeEnum.FILE.getCode())) {            //移动文件            RemoteFile remoteFile = new RemoteFile();            remoteFile.setOssId(Long.valueOf(toEnterpriseDto.getStorageId()));            RemoteFile storage = remoteFileService.copyFile(remoteFile, OssBucketOneEnum.ENTERPRISE_BUCKET.getCode(), OssModuleType.Enterprise);//            Storage storage = fileStorageUtils.copy(userId, username, FileEnums.ENTERPRISE_FILE, StorageFolderTypeEnum.TEMPLATE_BUCKET.getCode(), toEnterpriseDto.getStorageId(), null, null);            enterpriseFilesTree.setSuffix(storage.getFileSuffix());            enterpriseFilesTree.setStorageId(storage.getOssId().toString());            enterpriseFilesTree.setSize(storage.getFileSize());        }        enterpriseFilesTree.setParentId(parentId);        enterpriseFilesTree.setSize(toEnterpriseDto.getSize());        enterpriseFilesTree.setRealName(toEnterpriseDto.getRealName());        enterpriseFilesTree.setType(toEnterpriseDto.getType());        enterpriseFilesTree.setSuperiorsPath(toEnterpriseDto.getPath());        enterpriseFilesTree.setPath(toEnterpriseDto.getPath() + "/" + toEnterpriseDto.getRealName());        enterpriseFilesTree.setCreateId(userId);        enterpriseFilesTree.setCreateBy(username);        enterpriseFilesTree.setUpdateId(userId);        enterpriseFilesTree.setUpdateId(userId);        enterpriseFilesTree.setUpdateBy(username);//        enterpriseFilesTree.setParentId(parentId).setSize(toEnterpriseDto.getSize()).setRealName(toEnterpriseDto.getRealName())//            .setType(toEnterpriseDto.getType())//            .setSuperiorsPath(toEnterpriseDto.getPath())//            .setPath(toEnterpriseDto.getPath() + "/" + toEnterpriseDto.getRealName())//            .setCreateId(userId)//            .setCreateBy(username)//            .setUpdateId(userId)//            .setUpdateBy(username);        //更新路径        toEnterpriseDto.setSuperiorsPath(enterpriseFilesTree.getSuperiorsPath()).setPath(enterpriseFilesTree.getPath());//        }        //插入文件夹        if (count == 1) {            enterpriseFilesTree.setRemarks(abstractName);        }        insert(enterpriseFilesTree,true);//        saveBatch(enterpriseFilesTrees);        Long id = enterpriseFilesTree.getId();//        //表单文档//        if (toEnterpriseDto.getType().equals(FileTypeEnum.RICH_TEXT.getCode())) {//            String sysFormDocDtoJson = toEnterpriseDto.getFormDocJson();//            SysFormDocDto sysFormDocDto = JSONObject.parseObject(sysFormDocDtoJson, SysFormDocDto.class);////            //创建表单文档//            sysFormDocDto.setType("2");//            sysFormDocDto.setTreeNodeId(String.valueOf(enterpriseFilesTree.getId()));//            sysFormDocDto.setId(null);//            SysFormDoc insert = sysFormDocService.insert(sysFormDocDto);////            //复制表单文档下的文件到minio//            String storagesJson = toEnterpriseDto.getStoragesJson();//            List<Storage> storages = JSONObject.parseArray(storagesJson, Storage.class);//            for (Storage value : storages) {//                //临时库移动到企业库////                Storage storage = fileStorageUtils.moveTitle(userId, username, null, value.getRealName(), StorageFolderTypeEnum.FORM_DOC_FILES.getCode(), String.valueOf(value.getStorageId()), FileEnums.ENTERPRISE_FORM_DOC_FILE);////                Storage storage = fileStorageUtils.copy(userId, username, FileEnums.ENTERPRISE_FORM_DOC_FILE,//                    StorageFolderTypeEnum.FORM_DOC_FILES.getCode(), String.valueOf(value.getStorageId()), null, value.getRealName());//                //创建表单文档文件//                SysFormDocFileDto sysFormDocFileDto = new SysFormDocFileDto();//                sysFormDocFileDto.setTreeNodeId(String.valueOf(enterpriseFilesTree.getId()));//                sysFormDocFileDto.setFormDocId(String.valueOf(insert.getId()));//                sysFormDocFileDto.setStorageId(String.valueOf(storage.getStorageId()));//                sysFormDocFileDto.setFileName(storage.getRealName());//                sysFormDocFileDto.setSuffix(storage.getSuffix());//                sysFormDocFileDto.setSize(storage.getSize());//                sysFormDocFileService.insert(sysFormDocFileDto);//            }//        }        //权限继承        enterprisePermService.extendPerm(Long.valueOf(parentId), id);        //更新大小（第一层）        if (count == 1) {            setParentNodeSize(parentId, toEnterpriseDto.getSize(), 0);        }        count++;        for (PersonalToEnterpriseDto toEnterprise : list) {            createFolder(toEnterprise, userId, null, username, id.toString(), count);        }    }    @Override    public void toDify(List<Long> ids) {        for (Long id : ids) {            EnterpriseFilesTree byId = getById(id);            Long libraryId = byId.getLibraryId();            EnterpriseFilesTree byId1 = getById(libraryId);            String aiDatasetId = byId1.getAiDatasetId();            if (!StringUtils.isNullOrBlank(aiDatasetId)){                if (FileUtil.checkSuffix(byId.getSuffix())){                    RemoteDifyCreateByFileBo remoteDifyCreateByFileBo = new RemoteDifyCreateByFileBo();                    remoteDifyCreateByFileBo.setIndexing_technique("high_quality");                    RemoteDifyCreateByFileBo.ProcessingRule processingRule = new RemoteDifyCreateByFileBo.ProcessingRule();                    remoteDifyCreateByFileBo.setProcess_rule(processingRule);                    RemoteDifyCreateByFileBo.ProcessingRule.Rules rules = new RemoteDifyCreateByFileBo.ProcessingRule.Rules();                    processingRule.setRules(rules);                    processingRule.setMode("custom");                    ArrayList<RemoteDifyCreateByFileBo.ProcessingRule.Rules.PreProcessingRule> preProcessingRules = new ArrayList<>();                    rules.setPre_processing_rules(preProcessingRules);                    preProcessingRules.add(new RemoteDifyCreateByFileBo.ProcessingRule.Rules.PreProcessingRule("remove_extra_spaces", true));                    preProcessingRules.add(new RemoteDifyCreateByFileBo.ProcessingRule.Rules.PreProcessingRule("remove_urls_emails", true));                    rules.setSegmentation(new RemoteDifyCreateByFileBo.ProcessingRule.Rules.Segmentation("###", 500));                    String fileDatasetId = null;                    try {                        RemoteDifyCreateByFileVo byFile = remoteDifyService.createByFile(byId.getStorageId(), byId.getRealName(), aiDatasetId, remoteDifyCreateByFileBo);                        fileDatasetId = byFile.getDocument().getId();                    } catch (Exception e) {                        throw new RuntimeException("文件上传到dify失败:网络错误或者文件重名或者文件格式错误或者该知识库已被删除");                    }                    byId.setFileDatasetId(fileDatasetId);                    updateById(byId);                }            }        }    }    /**     * 根据模板创建企业知识库目录     * @param templateId 模板id     * @param enterpriseId 企业库顶级目录id     */    private void createByTemplate(String templateId,String enterpriseId){        EnterpriseFilesTree enterpriseFilesTree = getById(enterpriseId);        //创建知识库顶级文件夹        EnterpriseFolderTree enterpriseFolderTree = enterpriseFolderTreeMapper.selectById(templateId);        EnterpriseFilesTree convert = MapstructUtils.convert(enterpriseFolderTree, EnterpriseFilesTree.class);        convert.setId(null);        //设置路径        convert.setSuperiorsPath(enterpriseFilesTree.getPath());        if (null == enterpriseFilesTree.getPath()) {            convert.setPath("/" + enterpriseFilesTree.getRealName());        } else {            convert.setPath(enterpriseFilesTree.getPath() + "/" + convert.getRealName());        }        convert.setType(FileTypeEnum.FOLDER.getCode());        convert.setParentId(enterpriseId);        save(convert);        List<EnterpriseFolderTree> enterpriseFolderTrees = getFolderTreeChildren(templateId);        createByTemplateChild(enterpriseFolderTrees,convert,convert.getId());    }    /**     * 根据模板创建子级     * @param enterpriseFolderTrees 企业模板集合     * @param parentTree 作为父级的企业文档对象     * @param libraryId 企业知识库id     */    private void createByTemplateChild(List<EnterpriseFolderTree> enterpriseFolderTrees,EnterpriseFilesTree parentTree,Long libraryId){        for (EnterpriseFolderTree enterpriseFolderTree : enterpriseFolderTrees) {            //拿到模板的下级            List<EnterpriseFolderTree> folderTreeChildren = getFolderTreeChildren(String.valueOf(enterpriseFolderTree.getId()));            EnterpriseFilesTree convert = MapstructUtils.convert(enterpriseFolderTree, EnterpriseFilesTree.class);            //清空id 准备创建企业文件            convert.setId(null);            //设置上级            convert.setParentId(String.valueOf(parentTree.getId()));            //设置知识库id            convert.setLibraryId(libraryId);            if (convert.getType().equals(FileTypeEnum.FILE.getCode())){                //对文件进行copy                RemoteFile remoteFile = new RemoteFile();                remoteFile.setOssId(Long.valueOf(convert.getStorageId()));                RemoteFile copyFile = remoteFileService.copyFile(remoteFile, OssBucketOneEnum.ENTERPRISE_BUCKET.getCode(), OssModuleType.Enterprise);                convert.setStorageId(String.valueOf(copyFile.getOssId()));                convert.setEdition(copyFile.getVersionId());                convert.setEditionName(copyFile.getVersionName());            }            //设置路径            convert.setSuperiorsPath(parentTree.getPath());            if (null == parentTree.getPath()) {                convert.setPath("/" + parentTree.getRealName());            } else {                convert.setPath(parentTree.getPath() + "/" + convert.getRealName());            }            save(convert);            if (folderTreeChildren.size() != 0)                //给子级创建下级目录                createByTemplateChild(folderTreeChildren,convert,libraryId);        }    }    private List<EnterpriseFolderTree> getFolderTreeChildren(String id){        QueryWrapper<EnterpriseFolderTree> predicate = QueryHelpMybatisPlus.getPredicate(new EnterpriseFolderTreeQueryParam());        predicate.eq("parent_id",id);        return enterpriseFolderTreeMapper.selectList(predicate);    }    @Override    public void createFileToEs(Long dataId){        EnterpriseFilesTree newFileTree = getById(dataId);        if (newFileTree.getType().equals("folder")){        }else if(newFileTree.getType().equals("file")) {        }        List<String> list = new ArrayList<>();        list.add(PermTypeEnum.USER.getPermTypeName());        List<EnterpriseMemberVo> users = enterprisePermService.selectPermissionsByTreeNodeIdNew(newFileTree.getId(), JSONObject.toJSONString(list), null, null);        List<String> usersList = users.stream().map(EnterpriseMemberVo::getTypeId).collect(Collectors.toList());        List<String> list2 = new ArrayList<>();        list2.add(PermTypeEnum.DEPT.getPermTypeName());        List<EnterpriseMemberVo> depts = enterprisePermService.selectPermissionsByTreeNodeIdNew(newFileTree.getId(), JSONObject.toJSONString(list2), null, null);        List<String> deptList = depts.stream().map(EnterpriseMemberVo::getTypeId).collect(Collectors.toList());        List<String> list3 = new ArrayList<>();        list3.add(PermTypeEnum.JOB.getPermTypeName());        List<EnterpriseMemberVo> jobs = enterprisePermService.selectPermissionsByTreeNodeIdNew(newFileTree.getId(), JSONObject.toJSONString(list3), null, null);        List<String> jobsList = jobs.stream().map(EnterpriseMemberVo::getTypeId).collect(Collectors.toList());        List<String> list4 = new ArrayList<>();        list4.add(PermTypeEnum.ROLE.getPermTypeName());        List<EnterpriseMemberVo> roles = enterprisePermService.selectPermissionsByTreeNodeIdNew(newFileTree.getId(), JSONObject.toJSONString(list4), null, null);        List<String> rolesList = roles.stream().map(EnterpriseMemberVo::getTypeId).collect(Collectors.toList());        RemoteEsFilesTree build = RemoteEsFilesTree.builder().id(newFileTree.getId()).parentId(newFileTree.getParentId())            .createBy(Long.valueOf(newFileTree.getCreateId()))            .storageId(newFileTree.getStorageId())            .versionId(newFileTree.getEdition())            .versionName(newFileTree.getEditionName())            .teamId(newFileTree.getLibraryId().toString())            .realName(newFileTree.getRealName())            .suffix(newFileTree.getSuffix())            .size(newFileTree.getSize())            .libraryType(TreeEnum.ENTERPRISE.getType())            .userIdList(usersList)            .deptIdList(deptList)            .postIdList(jobsList)            .roleIdList(rolesList)            .type(newFileTree.getType()).build();        try {            String uuid = "";            if (newFileTree.getEsId() == null){                uuid = remoteOssEsService.insert(build);            }else {                build.setEsId(newFileTree.getEsId());                uuid = remoteOssEsService.update(build);            }            newFileTree.setEsId(uuid);            updateById(newFileTree);        } catch (Exception e) {            log.error("同步到es失败", e);        }    }}